# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=glm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.1
pkgrel=1
pkgdesc="C++ mathematics library for 3D software based on the OpenGL Shading Language (GLSL) specification (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://glm.g-truc.net/'
msys2_repository_url="https://github.com/g-truc/glm"
msys2_references=(
  'archlinux: glm'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/g-truc/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('9f3174561fd26904b23f0db5e560971cbf9b3cbda0b280f04d5c379d03bf234c')

build() {
  mkdir "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DGLM_TEST_ENABLE=OFF \
    "${_extra_config[@]}" \
    -DGLM_BUILD_LIBRARY=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share/doc
  cp -r "$srcdir"/${_realname}-${pkgver}/doc \
   "${pkgdir}"${MINGW_PREFIX}/share/doc/glm

  install -vDm 644 "$srcdir/"${_realname}-${pkgver}/copying.txt -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
